#include "ReactorTaskExecutor.h"
#include "Reactor.h"
#include "ReactorTask.h"

using namespace std;
using namespace network;
using namespace threadpool;

ThreadStatus
ReactorTaskExecutor::customAfterExecute(const shared_ptr<Task> &task, ThreadPool *pool) {
    if (task->getType() != "ReactorTask") {
        return ThreadStatus::ThreadContinue;
    }
    ReactorTask *reactor_task = dynamic_cast<ReactorTask*>(task.get());
    Reactor *reactor = reactor_task->getReactor();
    Event *event = reactor_task->getEvent();
    if (event->empty()) {
        lock_guard<mutex> lock(reactor->ready_event_set_mutex_);
        reactor->ready_event_set_.erase(reactor_task->getEvent());
    }
    event->setReady();
    return ThreadStatus::ThreadContinue;
}
